package cn.kgc.springboot.controller;

import cn.kgc.springboot.entity.Usr;
import cn.kgc.springboot.service.UserService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.*;

/**
 * @author 课工场
 * @date 2023/11/13
 * @description
 */
@RestController
@RequestMapping("users")
public class UserController {

    @Resource
    private UserService userService;

    @GetMapping
    public List<Usr>  getList(){

       List<Usr> usrs =   userService.list();


       return usrs;
    }

    @GetMapping("page")
    public Map<String, Object> getPage(Integer page, Integer limit){

        Page<Usr> usrPage = new Page<>(page, limit);
        userService.page(usrPage);

        List<Usr> records = usrPage.getRecords();
        long total = usrPage.getTotal();

        HashMap<String, Object> result = new HashMap<>();
        result.put("total",total);
        result.put("items",records);

        return result;
    }
}
